<template>
	<div>
		<el-card class="box-card">
			<span>学生后台</span>
			<el-button type="text" style="float: right; padding: 5px 0" @click="opendialog()">添加</el-button>
			<el-table :data="dataList" height="850px" border style="width: 100%" :stripe="true">
				<el-table-column type="index" label="序号" width="50" align="center">
				</el-table-column>
				<el-table-column prop="account" label="学号" width="180" sortable="">
				</el-table-column>
				<el-table-column prop="name" label="姓名" width="100">
				</el-table-column>
				<el-table-column prop="sex" label="姓别" width="50">
				</el-table-column>
				<el-table-column prop="info" label="自我介绍">
				</el-table-column>
				<el-table-column prop="counts" label="票数" align="center">
				</el-table-column>
				<el-table-column label="操作" width="180" sortable="">
					<template slot-scope="scope">
						<el-button type="danger" icon="el-icon-delete" circle
							@click="deleterow(scope.row.account)"></el-button>
					</template>
				</el-table-column>
			</el-table>

		</el-card>
		<add ref="add"></add>
	</div>

</template>

<script>
	import add from './add.vue'
	export default {
		data() {
			return {
				dataList: [],
				visible: false
			}
		},
		components: {
			add
		},
		methods: {
			opendialog() {
				// 父组件对子组件的引用
				this.$refs.add.dialogVisible = true;
			},
			deleterow(account) {
				this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http.get("api/admin?mark=delete&account=" + account).then((resp) => {
						this.$message({
							type: 'success',
							message: '删除成功!'
						});
						this.$router.go();
					})

				}).catch(() => {
					// 用户点击了取消按钮，这里可以什么也不做，或者给用户一个反馈  
					// 例如，可以使用 this.$message 来显示一个消息  
					this.$message({
						type: 'info',
						message: '已取消删除操作'
					});
				});
			},
		},
		mounted() {
			this.$http.get("/api/yearPeople").then((resp) => {
				if (resp.data.code == 200)
					this.dataList = resp.data.obj;
			})
		}

	}
</script>

<style>
</style>